﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IceDog.DNL.CSharp.DesignPattern.MVCPattern.StudentManage.Models;
using IceDog.DNL.CSharp.DesignPattern.MVCPattern.StudentManage.Views;

namespace IceDog.DNL.CSharp.DesignPattern.MVCPattern.StudentManage.Controllers
{
    public class StudentController
    {
        private List<Student> _students;
        private StudentView _view;

        public StudentController()
        {
            _students = new List<Student>
            {
                new Student("No.1","jimmy"),
                new Student("No.2","tom"),
                new Student("No.3","green")
            };
            _view = new StudentView();
        }

        public void GetStudents()
        {
            _view.ShowList(_students);
        }

        public void GetStudentByName(string name)
        {
            _view.ShowDetails(_students.First(s=>s.Name.Equals(name)));
        }

        public void UpdateStudent(string name,string newName)
        {
            var student=_students.First(s => s.Name.Equals(name));
            student.Name = newName;

        }
    }
}
